<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
	var taskId="${taskId}";
    var currentUserid='<shiro:principal property = "id"/>';
    $(function() {
    	setLeaveTodoValues();
    	var url='${path}/example/leave/completeTask/${taskId}';
    	if('${taskDefKey}'=='modifyApply'){
    		url='${path}/example/leave/modifyLeave/${taskId}';
    	}
        $('#leavehandleForm').form({
            url : url,
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    showMsg(result.msg);
                    parent.$.modalDialog.openner_dataGrid.datagrid('reload');
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    var form = $('#leavehandleForm');
                    parent.$.messager.alert('错误', result.msg, 'error');
                }
            }
        });
    });

    function removeLeaveAttr(data) {
       setFromAttrDisabled($('#leavehandleForm'),data,false);
       $("#leave_todo_leaveDate").datebox({disabled:false});
    }
    function setLeaveTodoValues(){
      $.ajax({
        url:'${ctxPath}/example/leave/toApproval/'+taskId,
        data:{"currentUserid":currentUserid},
        type:'post',
        dataType:'json',
        success:function(result){
          if(!isNull(result)){
            var leave=result.leave;
            var tasks=result.tasks;
            var comments=result.comments;
            $('#leave_todo_assigneeOrCandidateUser').text(result.assigneeOrCandidateUser);
            if(result.taskDefKey=='modifyApply'){
                removeLeaveAttr(leave);
                $('#leave_audit').hide();
                $('#leave_modify').show();
            }
            if(!isNull(leave)){
                setFromValues($('#leavehandleForm'),leave);
               $('#leave_todo_leaveDate').datebox('setValue', date2Str(leave.leaveDate));
            }
            if(!isNull(tasks)){
            var html='<tr><td style="text-align:right">下一步任务</td><td>';
              for(var i=0;i<tasks.length;i++){
                var task=tasks[i];
                html+='<div><b>'+task.taskName+'</b></div>'
                        +'<input type="hidden" name="'+task.taskDefKey+'_taskType" value="'+task.taskType+'"/>';
                        if(task.taskDefKey=='modifyApply'){
                            html+='<input type="hidden" name="' + task.taskDefKey + '_candidate_ids" value="' + leave.userid + '"/>'
                            + '<input type="text" class="easyui-text-2"  name="' + task.taskDefKey + '_candidate_name" readonly="readonly" value="' + leave.userName + '"/><br />';
                        }else{
                          if(task.taskType=='assignee'){
                            html+='<input type="hidden" name="'+task.taskDefKey+'_candidate_ids" id="'+task.taskDefKey+'_candidate_ids" value="'+task.candidate_ids+'"/>'
                            +'<input type="text" class="easyui-text-2" name="'+task.taskDefKey+'_candidate_name" id="'+task.taskDefKey+'_candidate_ids_disp"'
                            +'onfocus="selectUser(false,\''+task.taskDefKey+'_candidate_ids\',\''+task.taskDefKey+'_candidate_ids_disp\')" value="'+task.candidate_name+'"/>';
                          }
                          if(task.taskType == 'candidateUser'){
                            html+='<input type="hidden" name="'+task.taskDefKey+'_candidate_ids" id="'+task.taskDefKey+'_candidate_ids" value="'+task.candidate_ids+'"/>'
                            +'<input type="text" class="easyui-text-2" name="'+task.taskDefKey+'_candidate_name" id="'+task.taskDefKey+'_candidate_ids_disp"'
                            +'onfocus="selectUser(true,\''+task.taskDefKey+'_candidate_ids\',\''+task.taskDefKey+'_candidate_ids_disp\')" value="'+task.candidate_name+'"/>';
                          } 
                          if(task.taskType == 'candidateGroup'){
                            html+='<input type="hidden" name="'+task.taskDefKey+'_candidate_ids" id="'+task.taskDefKey+'_candidate_ids" value="'+task.candidate_ids+'"/>'
                            +'<input type="text" class="easyui-text-2" name="'+task.taskDefKey+'_candidate_name" id="'+task.taskDefKey+'_candidate_ids_disp"'
                            +'onfocus="selectRole(true,\''+task.taskDefKey+'_candidate_ids\',\''+task.taskDefKey+'_candidate_ids_disp\')" value="'+task.candidate_name+'"/>';
                          }
                      }
                     html+='<br />';
              }
               if((result.taskDefKey=='hrAudit')||(result.taskDefKey=='modifyApply')){
                     html+='<b>结束</b><br />';     
                }
              html+='</td></tr>';
              $('#leave_todo_table').append(html);
            }
            if(!isNull(comments)){
                if(comments.length>0) {
                    var commentHtml = '<tr> <td style="text-align:right">历史批注</td><td>';
                    for (var i = 0; i < comments.length; i++) {
                        var comment = comments[i];
                        commentHtml += '<p><b>任务名称：' + comment.taskName + '</b></p>'
                            + '<p>评论人：' + comment.userName + '</p>'
                            + '<p>评论时间：' + datetime2Str(comment.time) + '</p>'
                            + ' <p>评论内容：' + comment.comment + '</p>';
                    }
                    commentHtml += '</td></tr>';
                    $('#leave_todo_table').append(commentHtml);
                }
            }
          }
        }
      })
    }

</script>
<div class="easyui-layout" data-options="fit:true,border:false" >
    <div data-options="region:'center',border:false" style="overflow-x:hidden;overflow-y: auto;padding: 3px;" >
    	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fi-clock icon-blue'" onclick="queryHistoryCommentFun('${processInstanceId}')">历史批注</a>
    	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fi-arrow-left icon-blue'" onclick="fallbackFun('${processInstanceId}','${procDefId}','${taskId}','${taskDefKey}')">回退</a>
    	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fi-arrow-right icon-blue'" onclick="forwardFun('${processInstanceId}','${procDefId}','${taskId}','${taskDefKey}')">前进</a>
    	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fi-comments icon-blue'" onclick="doDelegateTask()">委派</a>
    	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fi-sound icon-blue'" onclick="doTransferTask();">转办</a>
    	<a href="${ctxPath}/process/graphHistoryProcessInstance?processInstanceId=${processInstanceId}" target="_blank" class="easyui-linkbutton" data-options="iconCls:'fi-photo icon-blue'">查看流程图</a>
        <form id="leavehandleForm" method="post">
            <h4 style="text-align: center;font-size: 14px">请假申请</h4>
          <input type="hidden" name="id"/>
        	<input type="hidden" name="processInstanceId" value="${processInstanceId}"/>
        	<input type="hidden" name="currentUserid" value='<shiro:principal property = "id"/>'/>
            <table class="grid">
            	<tr>
            		<td style="width:100px;">任务执行人</td>
            		<td id="leave_todo_assigneeOrCandidateUser"></td>
            	<td style="width:100px;">当前任务办理人</td>
            		<td><shiro:principal></shiro:principal></td>
            	</tr>
            	</table>
            	 <table class="grid" id="leave_todo_table">
 				<tr>
                     <td style="text-align:right">申请人</td>
                      <td>
                        <input name='userName'   type='text' placeholder='请输入申请人' class='easyui-text-2  span2'  disabled="disabled" readonly="readonly">
                        <input type="hidden" name="userid"/>
                     </td>
                  </tr> <tr>
                    <td style="text-align:right">标题</td>
                      <td>
                        <input name='title' id='title'  type='text' placeholder='请输入标题' class='easyui-text-2  span2' style="width:90%"  disabled="disabled">
                     </td>
                  </tr><tr>
                     <td style="text-align:right">请假时间</td>
                      <td>
                        <input name='leaveDate' id='leave_todo_leaveDate' type='text'  class='easyui-text-2 easyui-datebox  span2' data-options=''  style='height: 29px;' disabled="disabled">
                     </td>
                     </tr>
                    <tr>
                     <td style="text-align:right">天数</td>
                      <td>
                        <input name='days' id='days'  type='text' placeholder='请输入天数' class='easyui-text-2  span2'  disabled="disabled">
                     </td>
                  </tr> 
 			        	<tr>
                     <td style="text-align:right">请假原因</td>
                      <td>
                        <textarea name="reason" class="easyui-text-2 easyui-validatebox" data-options="required:true" style="height:50px;width:90%" disabled="disabled"></textarea>
                     </td>
                  </tr> 
                  <tr id="leave_audit">
                  <td style="text-align:right">审批意见</td>
                  	<td>
                  		<textarea style="width:90%;min-height:50px;" name="content" class="easyui-text-2"></textarea><br />
                  		<input type="radio" name="completeFlag"  value="true" class="input_button1" checked="checked"/>同意
            			<input type="radio" name="completeFlag"  value="false" class="input_button1"/>不同意
                  	</td>
                  </tr>
                  <tr style="display: none" id="leave_modify">
                    <td style="text-align: right">修改操作</td>
                    <td><input type="radio" name="reApply" value="true"
                      class="input_button1" checked="checked" />提交 <input type="radio"
                      name="reApply" value="false" class="input_button1" />取消提交</td>
                  </tr>
                
            </table>
        </form>
    </div>
</div>